package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author loe
 * @Date 2024-07-09
 */

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     * @return List<NursingLevelVo>
     */
    @Override
    public List<NursingLevelVo> searchAll() {
        return nursingLevelMapper.searchAll();
    }

    /**
     * 新增
     * @param nursingLevelDto
     */
    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setStatus(1);
        nursingLevelMapper.insert(nursingLevel);
    }

    /**
     * 条件分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> limitSearch(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.limitSearch(name, status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 根据id查询
     * @param id 护理等级ID
     * @return
     */
    @Override
    public NursingLevelVo getById(Long id) {
        return nursingLevelMapper.getById(id);
    }

    /**
     * 修改
     * @param nursingLevelDto
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 删除
     * @param id 护理等级ID
     */
    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    /**
     * 启用禁用
     * @param id 护理等级ID
     * @param status 状态，0：禁用，1：启用
     * @return
     */
    @Override
    public void setStatus(Long id, Integer status) {
        nursingLevelMapper.setStatus(id, status);
    }
}
